package com.starblink.library.widget.wishlist.cell

import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.enableCorner
import com.starblink.android.basic.ext.string
import com.starblink.android.basic.ext.visibleOrGone
import com.starblink.basic.ext.load
import com.starblink.library.widget.R
import com.starblink.library.widget.databinding.CellBoardWishlistBinding
import com.starblink.rocketreserver.fragment.WishListF

/**
 *  Create by yuanl at 2023/4/14
 **/
class BoardWishlistCell(
    binding: CellBoardWishlistBinding,
    private val click: ((toWishListId: String, name: String) -> Unit)? = null
) :
    BaseBindingVH<WishListF, CellBoardWishlistBinding>(
        binding
    ) {

    init {
        binding.img1.enableCorner(4000)
        binding.img2.enableCorner(4000)
        binding.img3.enableCorner(4000)
    }

    override fun onBind(
        model: WishListF,
        position: Int
    ) {
        itemView.setOnClickListener {
            click?.invoke(
                model.id, model.title
            )
        }

        binding.tvName.text = model.title
        binding.tvQuantity.text =
            "${model.productCount} ${if (model.productCount > 1) string(com.starblink.basic.style.R.string.items) else "Item"}"

        val imgUrl1 = model.productList?.getOrNull(0)?.productF?.mainImg
        val imgUrl2 = model.productList?.getOrNull(1)?.productF?.mainImg
        val imgUrl3 = model.productList?.getOrNull(2)?.productF?.mainImg
        binding.img1.visibleOrGone(imgUrl1?.isNotEmpty() == true) {
            load(imgUrl1)
        }
        binding.img2.visibleOrGone(imgUrl2?.isNotEmpty() == true) {
            load(imgUrl2)
        }
        binding.img3.visibleOrGone(imgUrl3?.isNotEmpty() == true) {
            load(imgUrl3)
        }
    }
}